git fetch -ap 이후 자동으로 머지된 브랜치를 삭제하는 명령어
git fetch -ap
위 명령어만으로는 로컬 브랜치들이 적절히 prune되지 않는 문제가 있다. 왜냐면 리모트 브랜치 위주로 브랜치를 삭제하기 때문이다. 그러면 어떻게 하면 머지되어 삭제된 브랜치를 찾아서 지울 수 있을까?
git branch --merged | grep -v '\*' | grep -vE '^\s*(main|dev)
### 🔍 Explanation:
- `git branch --merged`: list all merged local branches
- `grep -v '\*'`: exclude the currently checked-out branch (has `*`)
- `grep -vE ...`: exclude protected branches like `main`, `master`, `dev` (customize as needed)
- `awk '{print $1}'`: clean up spacing and extract the branch name
- `xargs git branch -D`: delete those branches forcefully
| awk '{print $1}' | xargs git branch -D
🔍 Explanation:
git branch --merged
: list all merged local branchesgrep -v '\*'
: exclude the currently checked-out branch (has*
)grep -vE ...
: exclude protected branches likemain
,master
,dev
(customize as needed)awk '{print $1}'
: clean up spacing and extract the branch namexargs git branch -D
: delete those branches forcefully